﻿/* ************************************************************
 * JUST TEST CODE -- NOT READY FOR PRODUCTION
 * Author:  Roy Penrod
 * 
 * Defines an asteroid.
 * 
 * Implements the JumpFleetGameLib.xMap.IPositionableObject
 * and JumpFleetGameLib.xMap.IUpdatableObject interfaces.
 * 
 * ************************************************************ */

using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Asteroid
{
    class Asteroid : JumpFleetGameLib.xMap.IPositionableObject, JumpFleetGameLib.xMap.IUpdatableObject
    {
        #region MEMBERS

        // holds the static sprite 
        private JumpFleetGameLib.xSprite.StaticSprite _sprite;

        // asteroid's position
        private Vector2 _currentPosition;

        // flag for whether the asteroid is visible
        private bool _visible;

        // asteroid's rotation angle
        private float _rotationAngle;

        // asteroid's rotation speed
        // degrees per second
        private float _rotationSpeed;

        // asteroid's rotation direction
        private bool _rotateClockwise;

        // stores the current position of the SectorMap origin
        private Vector2 _currentMapPosition;

        // asteroid's offset within the SectorMap
        private Vector2 _currentMapOffset;

        #endregion


        #region PROPERTIES

        public Vector2 CurrentPosition
        {
            get { return _currentPosition; }

            set 
            {
                _currentPosition = value;
                
                // sets the sprite's DrawPosition property
                _sprite.DrawPosition = value;
            }
        }

        public bool Visible
        {
            get { return _visible; }

            set
            {
                _visible = value;

                // sets the sprite's Visible property
                _sprite.Visible = value;
            }
        }

        public float RotationAngle
        {
            get { return _rotationAngle; }

            set
            {
                _rotationAngle = value;

                // sets the sprite's RotationAmount property
                _sprite.RotationAmount = value;
            }
        }

        public float RotationSpeed
        {
            get { return _rotationSpeed; }

            set
            {
                _rotationSpeed = value;
            }
        }

        public bool RotateClockwise
        {
            get { return _rotateClockwise; }

            set
            {
                _rotateClockwise = value;

            }
        }

        public Vector2 CurrentMapOffset
        {
            get { return _currentMapOffset; }

            set { _currentMapOffset = value; }
        }

        public Vector2 CurrentMapPosition
        {
            set
            {                
                _currentMapPosition = value;

                CurrentPosition = new Vector2(_currentMapPosition.X + _currentMapOffset.X, _currentMapPosition.Y + _currentMapOffset.Y);
            }
        }

        public float Layer
        {
            set { _sprite.Layer = value; }
        }

        #endregion


        #region CONSTRUCTORS

        public Asteroid(JumpFleetGameLib.xSprite.StaticSprite sprite, float rotationSpeed, bool rotateClockwise)
        {
            // assigns the parameters
            _sprite = sprite;
            Visible = false;
            _rotationSpeed = rotationSpeed;
            _rotateClockwise = rotateClockwise;
        }

        #endregion


        #region METHODS

        public void Update(GameTime gameTime)
        {
            if (_rotateClockwise)
                RotationAngle += RotationSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            else
                RotationAngle -= RotationSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
           // _currentMapOffset +=  new Vector2( 1.0f,0.0f);
        }

        #endregion



        public Vector2 Target
        {
            get;
            set;
        }
    } // <-- end class
} // <-- end namespace
